/*
This code will provide the coefficients for
Table 2:Difference-in-difference estimates of the associations between ACA reforms and MA enrollment and payment
*/

log using "$logs\Table2.txt", replace text name(table2)

putexcel set "$output\Table2", modify

putexcel ///
A1="Counties in higher benchmark cut group" ///
 ///
C1="Higher benchmark cut counties" ///
E1="Lower benchmark cut counties" ///
 ///
G1="Unadjusted difference-in-differences" ///
 ///
H1="Regression estimates of difference-in-differences" ///
H2="Coefficient" ///
I2="(95% CI)" ///
J2="P value" ///
 ///
A3="Outcome: MA Enrollment%" ///
A8="Outcome: MA payment, $ per beneficiary per mo" ///
 ///
C2="Pre-ACA" ///
D2="After phase in" ///
E2="Pre-ACA" ///
F2="After phase in" ///
 ///
B3="Top 25%" ///
B4="Top 50%" ///
B5="Top 10%" ///
B8="Top 25%" ///
B9="Top 50%" ///
B10="Top 10%"

* Outcome: Medicare Advantage enrollment

use "$data_deri\enroll_panel", clear

mean penetration [aweight=eligibles11], over(q4_prop_flag phaseIn post)
matrix table = r(table)
matrix means = (round(table[1,5],.001), round(table[1,6],.001), round(table[1,1],.001), round(table[1,2],.001))
putexcel C3 = matrix(means) G3 = (round(table[1,6],.001) - round(table[1,5],.001) - (round(table[1,2],.001)-round(table[1,1],.001)))
mean penetration [aweight=eligibles11], over(med_prop_flag phaseIn post)
matrix table = r(table)
matrix means = (round(table[1,5],.001), round(table[1,6],.001), round(table[1,1],.001), round(table[1,2],.001))
putexcel C4 = matrix(means) G4 = (round(table[1,6],.001) - round(table[1,5],.001) - (round(table[1,2],.001)-round(table[1,1],.001)))
mean penetration [aweight=eligibles11], over(q10_prop_flag phaseIn post)
matrix table = r(table)
matrix means = (round(table[1,5],.001), round(table[1,6],.001), round(table[1,1],.001), round(table[1,2],.001))
putexcel C5 = matrix(means) G5 = (round(table[1,6],.001) - round(table[1,5],.001) - (round(table[1,2],.001)-round(table[1,1],.001)))

xtreg penetration ib2011.year phaseIn##q4_prop_flag post##q4_prop_flag [aweight=eligibles11], fe vce(robust)
matrix results = r(table)
local b = round(results["b","1.post#1.q4_prop_flag"],.001)
putexcel H3 = `b'
local ll = round(results["ll","1.post#1.q4_prop_flag"],.001)
local ul = round(results["ul","1.post#1.q4_prop_flag"],.001)
putexcel I3 = "(`ll' to `ul')"
local p = round(results["pvalue","1.post#1.q4_prop_flag"],.001)
putexcel J3 = `p'

xtreg penetration ib2011.year phaseIn##med_prop_flag post##med_prop_flag [aweight=eligibles11], fe vce(robust)
matrix results = r(table)
local b = round(results["b","1.post#1.med_prop_flag"],.001)
putexcel H4 = `b'
local ll = round(results["ll","1.post#1.med_prop_flag"],.001)
local ul = round(results["ul","1.post#1.med_prop_flag"],.001)
putexcel I4 = "(`ll' to `ul')"
local p = round(results["pvalue","1.post#1.med_prop_flag"],.001)
putexcel J4 = `p'

xtreg penetration ib2011.year phaseIn##q10_prop_flag post##q10_prop_flag [aweight=eligibles11], fe vce(robust)
matrix results = r(table)
local b = round(results["b","1.post#1.q10_prop_flag"],.001)
putexcel H5 = `b'
local ll = round(results["ll","1.post#1.q10_prop_flag"],.001)
local ul = round(results["ul","1.post#1.q10_prop_flag"],.001)
putexcel I5 = "(`ll' to `ul')"
local p = round(results["pvalue","1.post#1.q10_prop_flag"],.001)
putexcel J5 = `p'


* Outcome: Medicare Advantage payment ($ per beneficiary per month)

use "$data_deri\payment_panel", clear

mean tot_payment_ra [aweight = imp_enrl], over(q4_prop_flag phaseIn post)
matrix table = r(table)
matrix means = (round(table[1,5],.001), round(table[1,6],.001), round(table[1,1],.001), round(table[1,2],.001))
putexcel C8 = matrix(means) G8 = (round(table[1,6],.001) - round(table[1,5],.001) - (round(table[1,2],.001)-round(table[1,1],.001)))
mean tot_payment_ra [aweight = imp_enrl], over(med_prop_flag phaseIn post)
matrix table = r(table)
matrix means = (round(table[1,5],.001), round(table[1,6],.001), round(table[1,1],.001), round(table[1,2],.001))
putexcel C9 = matrix(means) G9 = (round(table[1,6],.001) - round(table[1,5],.001) - (round(table[1,2],.001)-round(table[1,1],.001)))
mean tot_payment_ra [aweight = imp_enrl], over(q10_prop_flag phaseIn post)
matrix table = r(table)
matrix means = (round(table[1,5],.001), round(table[1,6],.001), round(table[1,1],.001), round(table[1,2],.001))
putexcel C10 = matrix(means) G10 = (round(table[1,6],.001) - round(table[1,5],.001) - (round(table[1,2],.001)-round(table[1,1],.001)))

xtreg tot_payment_ra ib2011.year phaseIn##q4_prop_flag post##q4_prop_flag [aweight = imp_enrl], fe vce(robust)
matrix results = r(table)
local b = round(results["b","1.post#1.q4_prop_flag"],.001)
putexcel H8 = `b'
local ll = round(results["ll","1.post#1.q4_prop_flag"],.001)
local ul = round(results["ul","1.post#1.q4_prop_flag"],.001)
putexcel I8 = "(`ll' to `ul')"
local p = round(results["pvalue","1.post#1.q4_prop_flag"],.001)
putexcel J8 = `p'

xtreg tot_payment_ra ib2011.year phaseIn##med_prop_flag post##med_prop_flag [aweight = imp_enrl], fe vce(robust)
matrix results = r(table)
local b = round(results["b","1.post#1.med_prop_flag"],.001)
putexcel H9 = `b'
local ll = round(results["ll","1.post#1.med_prop_flag"],.001)
local ul = round(results["ul","1.post#1.med_prop_flag"],.001)
putexcel I9 = "(`ll' to `ul')"
local p = round(results["pvalue","1.post#1.med_prop_flag"],.001)
putexcel J9 = `p'

xtreg tot_payment_ra ib2011.year phaseIn##q10_prop_flag post##q10_prop_flag [aweight = imp_enrl], fe vce(robust)
matrix results = r(table)
local b = round(results["b","1.post#1.q10_prop_flag"],.001)
putexcel H10 = `b'
local ll = round(results["ll","1.post#1.q10_prop_flag"],.001)
local ul = round(results["ul","1.post#1.q10_prop_flag"],.001)
putexcel I10 = "(`ll' to `ul')"
local p = round(results["pvalue","1.post#1.q10_prop_flag"],.001)
putexcel J10 = `p'

log close table2
